<template>
  <div>
    <el-dialog :title="'选择分配的用户'" :visible.sync="Configuration" width="1050px" :append-to-body="true" :close-on-click-modal="false">
      <el-row :span="24">
        <el-col :span="2" style="margin-right: -40px !important;">
          <label style="line-height: 50px">姓名：</label>
        </el-col>
        <el-col :span="6" style="margin-right: 50px">
          <el-input v-model="realName" placeholder="请输入内容"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" @click="findByUser()">查询</el-button>&nbsp;&nbsp;
          <el-button type="primary" @click="resets()">重置</el-button>
        </el-col>
        <el-col :span="6">
          <el-button style="float: right" type="success" v-throttle="[save]">确 定</el-button>
          <!--                    <el-button @click="toggleSelection()">关 闭</el-button>-->
        </el-col>
      </el-row>
      <el-table
        ref="singleTable"
        :data="assessInfoData"
        tooltip-effect="dark"
        style="width: 100%"
        highlight-current-row
        @current-change="handleSelectionChange"
      >
        <el-table-column label="选择" width="55">
          <template slot-scope="scope">
            <el-checkbox v-model="scope.row.checked"></el-checkbox>
          </template>
        </el-table-column>
        <el-table-column label="序号" type="index" width="175" align="center"></el-table-column>
        <el-table-column label="姓名" prop="realName" align="center" width="220"></el-table-column>
        <el-table-column prop="deptName" label="所属部门" align="center" width="220"></el-table-column>
        <el-table-column label="操作" align="center">
          <template>
            <el-button type="text">选择</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer">
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="1"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
        <br />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import dbl from '@/utils/dbl'
import axios from 'axios'

export default {
  data () {
    return {
      Configuration: false,
      assessInfoData: [],
      currentSelectItem: {
        userId: '',
        realName: ''

      },// 当前选中的值
      index: "",
      realName: '',
      pagesize: 10,
      currentPage: 1,
      total: 0
    }
  },
  methods: {
    toggleSelection () {
      this.currentSelectItem.userId = '';
      this.Configuration = false;
      this.resets()
    },
    handleSizeChange (val) {
      this.pagesize = val;
      this.getList();
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      this.getList();
    },
    findByUser () {
      const loading = this.$loading({
        lock: true,
        text: '数据处理中'
      });
      const config = {
        headers: { 'Authorization': dbl.get('token'), }
      };
      var keys = "?size=" + this.pagesize + "&current=" + this.currentPage;
      if (this.realName != '') {
        keys += "&realName=" + this.realName
      }
      axios.get(" /api/flowTaskResultAssignee/toUserList" + keys, config).then(response => {
        this.total = response.data.data.total;
        this.size = response.data.data.pages;
        this.assessInfoData = response.data.data.records;
        for (var i = 0; i < this.assessInfoData.length; i++) {
          this.assessInfoData[i].checked = false;
          this.assessInfoData[i].id = i;
        }
        loading.close()
      }).catch(e => {
        loading.close()
      })
    },
    resets () {
      this.realName = '';
    },
    save () {
      if (this.currentSelectItem === null || this.currentSelectItem.userId === '' || this.currentSelectItem.userId === null) {
        this.$message.warning("请指定任务办理人");
      } else {
        const loading = this.$loading({
          lock: true,
          text: '数据处理中'
        });
        const config = {
          headers: { 'Authorization': dbl.get('token'), }
        };
        var that = this
        axios.get(" /api/processMgr/doDelegateTask/" + this.index + "/" + this.currentSelectItem.userId + "/" + this.currentSelectItem.realName, config).then(response => {
          this.$message.success(response.data.msg);
          loading.close();
          this.$emit('flowTask', 1);
          this.toggleSelection();
        }).catch(e => {
          loading.close()
        })
      }
    },
    handleSelectionChange (row) {
      this.assessInfoData.forEach(item => {
        if (item.id !== row.id) {
          item.checked = false
        } else {
          item.checked = true
        }
      });
      this.currentSelectItem = row
    },
    show (data) {
      this.index = data;
      this.Configuration = true;
      this.getList()
    },
    getList () {
      const loading = this.$loading({
        lock: true,
        text: '数据处理中'
      });
      const config = {
        headers: { 'Authorization': dbl.get('token'), }
      };
      this.assessInfoData = [];
      var key = "?size=" + this.pagesize + "&current=" + this.currentPage;
      axios.get(" /api/flowTaskResultAssignee/toUserList" + key, config).then(response => {
        this.total = response.data.data.total;
        this.size = response.data.data.pages;
        this.assessInfoData = response.data.data.records;
        for (var i = 0; i < this.assessInfoData.length; i++) {
          this.assessInfoData[i].checked = false;
          this.assessInfoData[i].id = i;
        }
        loading.close()
      }).catch(e => {
        loading.close()
      })
    },
  },

}
</script>

<style scoped lang='scss'>
@include formWrap(4);
</style>

